package com.jiaming.restaurant.api.foodtable.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiaming.restaurant.api.foodtable.bean.entity.FoodTable;
import com.jiaming.restaurant.api.foodtable.mapper.FoodTableMapper;
import com.jiaming.restaurant.api.foodtable.service.IFoodTableService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dragon
 * @create 2020-12-29 11:27
 */
@Service
public class FoodTableServiceImpl extends ServiceImpl<FoodTableMapper, FoodTable>
        implements IFoodTableService {

    @Override
    public List<FoodTable> list(FoodTable foodTable) {
        QueryWrapper<FoodTable> query = Wrappers.query();
        Integer restaurantId = foodTable.getRestaurantId();
        query.eq("restaurant_id", restaurantId);
        Integer num = foodTable.getNum();
        if (num != null && num > 0) {
            query.eq("num", num);
        }
        Integer status = foodTable.getStatus();
        if (status != null && status > 0) {
            query.eq("status", status);
        }
        query.orderByDesc("update_time");
        return this.list(query);
    }

    @Override
    public List<FoodTable> getByRest(Integer restId) {
        QueryWrapper<FoodTable> query = Wrappers.query();
        query.eq("restaurant_id", restId);
        return this.list(query);
    }
}
